{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:47:51.296437Z",
     "start_time": "2021-07-14T12:47:51.287437Z"
    }
   },
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import toad\n",
    "import matplotlib\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.model_selection import train_test_split\n",
    "from xgboost import XGBClassifier\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.metrics import f1_score\n",
    "\n",
    "np.set_printoptions(suppress=True)\n",
    "pd.set_option('display.width', 180)\n",
    "pd.set_option('display.max_rows', None)\n",
    "pd.set_option('display.max_columns', 100)\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:35:41.304684Z",
     "start_time": "2021-07-14T12:35:40.576642Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>branch_id</th>\n",
       "      <th>supplier_id</th>\n",
       "      <th>manufacturer_id</th>\n",
       "      <th>area_id</th>\n",
       "      <th>employee_code_id</th>\n",
       "      <th>mobileno_flag</th>\n",
       "      <th>idcard_flag</th>\n",
       "      <th>Driving_flag</th>\n",
       "      <th>passport_flag</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>year_of_birth</th>\n",
       "      <th>disbursed_date</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>employment_type</th>\n",
       "      <th>age</th>\n",
       "      <th>loan_default</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>105691</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>384989</td>\n",
       "      <td>666207</td>\n",
       "      <td>666207</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31324</td>\n",
       "      <td>68657</td>\n",
       "      <td>0</td>\n",
       "      <td>535</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>645</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>300</td>\n",
       "      <td>8169</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>86</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>0.456239</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>384989</td>\n",
       "      <td>666207</td>\n",
       "      <td>666207</td>\n",
       "      <td>8169</td>\n",
       "      <td>1.73</td>\n",
       "      <td>81</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>2.50</td>\n",
       "      <td>1968</td>\n",
       "      <td>2019</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>51</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>24938</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>268670</td>\n",
       "      <td>387994</td>\n",
       "      <td>387994</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>53078</td>\n",
       "      <td>65565</td>\n",
       "      <td>1</td>\n",
       "      <td>767</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>959</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>691</td>\n",
       "      <td>2400</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>0.809548</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>268670</td>\n",
       "      <td>387994</td>\n",
       "      <td>387994</td>\n",
       "      <td>2400</td>\n",
       "      <td>1.44</td>\n",
       "      <td>161</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.33</td>\n",
       "      <td>1992</td>\n",
       "      <td>2019</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>104389</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3519013</td>\n",
       "      <td>3613854</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>53639</td>\n",
       "      <td>67501</td>\n",
       "      <td>56</td>\n",
       "      <td>138</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2766</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>832</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>55</td>\n",
       "      <td>0</td>\n",
       "      <td>0.794640</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3519013</td>\n",
       "      <td>3613854</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>1.02</td>\n",
       "      <td>3576048</td>\n",
       "      <td>0</td>\n",
       "      <td>0.99</td>\n",
       "      <td>3.00</td>\n",
       "      <td>1991</td>\n",
       "      <td>2019</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54688</td>\n",
       "      <td>43</td>\n",
       "      <td>13</td>\n",
       "      <td>6</td>\n",
       "      <td>1867106</td>\n",
       "      <td>2484678</td>\n",
       "      <td>2486856</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>62513</td>\n",
       "      <td>75661</td>\n",
       "      <td>50</td>\n",
       "      <td>211</td>\n",
       "      <td>2</td>\n",
       "      <td>16</td>\n",
       "      <td>1415</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>464</td>\n",
       "      <td>4320912</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>19</td>\n",
       "      <td>91</td>\n",
       "      <td>0</td>\n",
       "      <td>0.826225</td>\n",
       "      <td>43</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "      <td>1867106</td>\n",
       "      <td>2484678</td>\n",
       "      <td>2486856</td>\n",
       "      <td>4320912</td>\n",
       "      <td>1.33</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.42</td>\n",
       "      <td>1964</td>\n",
       "      <td>2019</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>63894</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>34439</td>\n",
       "      <td>62616</td>\n",
       "      <td>6</td>\n",
       "      <td>216</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>1186</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.550003</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1995</td>\n",
       "      <td>2019</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "0       105691                     4                            3                        0                         384989                      666207   \n",
       "1        24938                     7                            2                        0                         268670                      387994   \n",
       "2       104389                     5                            4                        1                        3519013                     3613854   \n",
       "3        54688                    43                           13                        6                        1867106                     2484678   \n",
       "4        63894                     0                            0                        0                              0                           0   \n",
       "\n",
       "   main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "0                       666207                    0                           0                       0                             0                          0   \n",
       "1                       387994                    0                           0                       0                             0                          0   \n",
       "2                      3576048                    0                           0                       0                             0                          0   \n",
       "3                      2486856                    0                           0                       0                             0                          0   \n",
       "4                            0                    0                           0                       0                             0                          0   \n",
       "\n",
       "   sub_account_disbursed_loan  disbursed_amount  asset_cost  branch_id  supplier_id  manufacturer_id  area_id  employee_code_id  mobileno_flag  idcard_flag  Driving_flag  \\\n",
       "0                           0             31324       68657          0          535                2        0               645              1            1             0   \n",
       "1                           0             53078       65565          1          767                1        1               959              1            1             0   \n",
       "2                           0             53639       67501         56          138                2        3              2766              1            1             0   \n",
       "3                           0             62513       75661         50          211                2       16              1415              1            1             0   \n",
       "4                           0             34439       62616          6          216                2        4              1186              1            1             0   \n",
       "\n",
       "   passport_flag  credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  last_six_month_defaulted_no  average_age  credit_history  \\\n",
       "0              0           300                          8169                            0                           0                            0           86              18   \n",
       "1              0           691                          2400                            0                           1                            0           13              28   \n",
       "2              0           832                             0                            0                           1                            0           27              55   \n",
       "3              0           464                       4320912                            0                           7                            4           19              91   \n",
       "4              0             0                             0                            0                           0                            0            0               0   \n",
       "\n",
       "   enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  total_inactive_loan_no  main_account_inactive_loan_no  total_overdue_no  \\\n",
       "0            0             0.456239                      4                             1                       0                              1                 0   \n",
       "1            0             0.809548                      7                             5                       0                              5                 0   \n",
       "2            0             0.794640                      5                             1                       0                              1                 1   \n",
       "3            0             0.826225                     43                            30                       0                             30                 6   \n",
       "4            1             0.550003                      0                             0                       0                              0                 0   \n",
       "\n",
       "   total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  outstanding_disburse_ratio  main_account_tenure  sub_account_tenure  \\\n",
       "0                  384989               666207                666207                   8169                        1.73                   81                   0   \n",
       "1                  268670               387994                387994                   2400                        1.44                  161                   0   \n",
       "2                 3519013              3613854               3576048                      0                        1.02              3576048                   0   \n",
       "3                 1867106              2484678               2486856                4320912                        1.33                    0                   0   \n",
       "4                       0                    0                     0                      0                        1.00                    0                   0   \n",
       "\n",
       "   disburse_to_sactioned_ratio  active_to_inactive_act_ratio  year_of_birth  disbursed_date  Credit_level  employment_type  age  loan_default  \n",
       "0                         1.00                          2.50           1968            2019             1                0   51             0  \n",
       "1                         1.00                          1.33           1992            2019             9                0   27             0  \n",
       "2                         0.99                          3.00           1991            2019            13                1   28             0  \n",
       "3                         1.00                          1.42           1964            2019             3                1   55             0  \n",
       "4                         1.00                          1.00           1995            2019            -1                0   24             0  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv(r\"D:/LKM/vehicle_loan_default/data/train.csv\")\n",
    "train['outstanding_disburse_ratio'] = train['outstanding_disburse_ratio'].replace([np.inf, -np.inf], 0)\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:33:39.903740Z",
     "start_time": "2021-07-14T12:33:39.386711Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>customer_id</th>\n",
       "      <th>main_account_loan_no</th>\n",
       "      <th>main_account_active_loan_no</th>\n",
       "      <th>main_account_overdue_no</th>\n",
       "      <th>main_account_outstanding_loan</th>\n",
       "      <th>main_account_sanction_loan</th>\n",
       "      <th>main_account_disbursed_loan</th>\n",
       "      <th>sub_account_loan_no</th>\n",
       "      <th>sub_account_active_loan_no</th>\n",
       "      <th>sub_account_overdue_no</th>\n",
       "      <th>sub_account_outstanding_loan</th>\n",
       "      <th>sub_account_sanction_loan</th>\n",
       "      <th>sub_account_disbursed_loan</th>\n",
       "      <th>disbursed_amount</th>\n",
       "      <th>asset_cost</th>\n",
       "      <th>branch_id</th>\n",
       "      <th>supplier_id</th>\n",
       "      <th>manufacturer_id</th>\n",
       "      <th>area_id</th>\n",
       "      <th>employee_code_id</th>\n",
       "      <th>mobileno_flag</th>\n",
       "      <th>idcard_flag</th>\n",
       "      <th>Driving_flag</th>\n",
       "      <th>passport_flag</th>\n",
       "      <th>credit_score</th>\n",
       "      <th>main_account_monthly_payment</th>\n",
       "      <th>sub_account_monthly_payment</th>\n",
       "      <th>last_six_month_new_loan_no</th>\n",
       "      <th>last_six_month_defaulted_no</th>\n",
       "      <th>average_age</th>\n",
       "      <th>credit_history</th>\n",
       "      <th>enquirie_no</th>\n",
       "      <th>loan_to_asset_ratio</th>\n",
       "      <th>total_account_loan_no</th>\n",
       "      <th>sub_account_inactive_loan_no</th>\n",
       "      <th>total_inactive_loan_no</th>\n",
       "      <th>main_account_inactive_loan_no</th>\n",
       "      <th>total_overdue_no</th>\n",
       "      <th>total_outstanding_loan</th>\n",
       "      <th>total_sanction_loan</th>\n",
       "      <th>total_disbursed_loan</th>\n",
       "      <th>total_monthly_payment</th>\n",
       "      <th>outstanding_disburse_ratio</th>\n",
       "      <th>main_account_tenure</th>\n",
       "      <th>sub_account_tenure</th>\n",
       "      <th>disburse_to_sactioned_ratio</th>\n",
       "      <th>active_to_inactive_act_ratio</th>\n",
       "      <th>year_of_birth</th>\n",
       "      <th>disbursed_date</th>\n",
       "      <th>Credit_level</th>\n",
       "      <th>employment_type</th>\n",
       "      <th>age</th>\n",
       "      <th>loan_default</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.00000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.0</td>\n",
       "      <td>150000.0</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.00</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>1.500000e+05</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.0</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "      <td>150000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>99944.368847</td>\n",
       "      <td>2.447133</td>\n",
       "      <td>1.045500</td>\n",
       "      <td>0.153427</td>\n",
       "      <td>1.670825e+05</td>\n",
       "      <td>2.225586e+05</td>\n",
       "      <td>2.221730e+05</td>\n",
       "      <td>0.060133</td>\n",
       "      <td>0.027967</td>\n",
       "      <td>0.007293</td>\n",
       "      <td>5.416077e+03</td>\n",
       "      <td>7.385876e+03</td>\n",
       "      <td>7.268286e+03</td>\n",
       "      <td>54238.47824</td>\n",
       "      <td>7.580399e+04</td>\n",
       "      <td>29.286380</td>\n",
       "      <td>724.978987</td>\n",
       "      <td>2.260600</td>\n",
       "      <td>5.614153</td>\n",
       "      <td>1207.022880</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.023013</td>\n",
       "      <td>0.002153</td>\n",
       "      <td>291.228720</td>\n",
       "      <td>1.295898e+04</td>\n",
       "      <td>2.938682e+02</td>\n",
       "      <td>0.384900</td>\n",
       "      <td>0.095687</td>\n",
       "      <td>8.027107</td>\n",
       "      <td>13.128353</td>\n",
       "      <td>0.203433</td>\n",
       "      <td>0.723558</td>\n",
       "      <td>2.507267</td>\n",
       "      <td>1.401633</td>\n",
       "      <td>0.032167</td>\n",
       "      <td>1.433800</td>\n",
       "      <td>0.160720</td>\n",
       "      <td>1.724986e+05</td>\n",
       "      <td>2.299445e+05</td>\n",
       "      <td>2.294413e+05</td>\n",
       "      <td>1.325285e+04</td>\n",
       "      <td>inf</td>\n",
       "      <td>5.169842e+04</td>\n",
       "      <td>2.773138e+03</td>\n",
       "      <td>6.506428e+02</td>\n",
       "      <td>1.438740</td>\n",
       "      <td>1984.867900</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>3.132360</td>\n",
       "      <td>0.487507</td>\n",
       "      <td>34.132100</td>\n",
       "      <td>0.176967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>57629.110557</td>\n",
       "      <td>5.197172</td>\n",
       "      <td>1.952708</td>\n",
       "      <td>0.542496</td>\n",
       "      <td>9.808619e+05</td>\n",
       "      <td>2.840313e+06</td>\n",
       "      <td>2.844075e+06</td>\n",
       "      <td>0.652912</td>\n",
       "      <td>0.325185</td>\n",
       "      <td>0.111236</td>\n",
       "      <td>1.617336e+05</td>\n",
       "      <td>1.742796e+05</td>\n",
       "      <td>1.735824e+05</td>\n",
       "      <td>12835.46104</td>\n",
       "      <td>1.879745e+04</td>\n",
       "      <td>19.335456</td>\n",
       "      <td>625.725640</td>\n",
       "      <td>1.403826</td>\n",
       "      <td>5.513141</td>\n",
       "      <td>812.442074</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.149946</td>\n",
       "      <td>0.046354</td>\n",
       "      <td>339.282431</td>\n",
       "      <td>1.508468e+05</td>\n",
       "      <td>1.304782e+04</td>\n",
       "      <td>0.962877</td>\n",
       "      <td>0.382359</td>\n",
       "      <td>13.830386</td>\n",
       "      <td>21.125146</td>\n",
       "      <td>0.696590</td>\n",
       "      <td>0.113621</td>\n",
       "      <td>5.273201</td>\n",
       "      <td>3.924056</td>\n",
       "      <td>0.429154</td>\n",
       "      <td>3.964609</td>\n",
       "      <td>0.557779</td>\n",
       "      <td>9.969156e+05</td>\n",
       "      <td>2.847267e+06</td>\n",
       "      <td>2.850957e+06</td>\n",
       "      <td>1.515095e+05</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.614563e+06</td>\n",
       "      <td>1.043622e+05</td>\n",
       "      <td>1.312314e+05</td>\n",
       "      <td>0.789844</td>\n",
       "      <td>9.813379</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.268384</td>\n",
       "      <td>0.561527</td>\n",
       "      <td>9.813379</td>\n",
       "      <td>0.381642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-6.678296e+06</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-5.746470e+05</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>13320.00000</td>\n",
       "      <td>3.700000e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.124130</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-6.678296e+06</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>-110000.33</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1950.000000</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>50069.750000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>46973.00000</td>\n",
       "      <td>6.571900e+04</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>212.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>494.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.664456</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1978.000000</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>26.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>99887.500000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>53703.00000</td>\n",
       "      <td>7.092500e+04</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>544.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>1107.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>14.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.741398</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1987.000000</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>149916.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.545900e+04</td>\n",
       "      <td>6.360000e+04</td>\n",
       "      <td>6.150850e+04</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>60220.00000</td>\n",
       "      <td>7.913000e+04</td>\n",
       "      <td>45.000000</td>\n",
       "      <td>1091.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>1833.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>680.000000</td>\n",
       "      <td>1.989000e+03</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.809578</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.788800e+04</td>\n",
       "      <td>6.690000e+04</td>\n",
       "      <td>6.500000e+04</td>\n",
       "      <td>2.076000e+03</td>\n",
       "      <td>1.26</td>\n",
       "      <td>2.500000e+01</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "      <td>1.670000</td>\n",
       "      <td>1993.000000</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>41.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>199716.000000</td>\n",
       "      <td>354.000000</td>\n",
       "      <td>144.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>9.652492e+07</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>52.000000</td>\n",
       "      <td>36.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>3.603285e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>2.688820e+07</td>\n",
       "      <td>990572.00000</td>\n",
       "      <td>1.628992e+06</td>\n",
       "      <td>81.000000</td>\n",
       "      <td>2933.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>3255.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>890.000000</td>\n",
       "      <td>2.076655e+07</td>\n",
       "      <td>3.246710e+06</td>\n",
       "      <td>35.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>0.937987</td>\n",
       "      <td>354.000000</td>\n",
       "      <td>344.000000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>344.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>9.652492e+07</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>2.076655e+07</td>\n",
       "      <td>inf</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>1.980000e+07</td>\n",
       "      <td>5.000000e+07</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>2001.000000</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>69.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         customer_id  main_account_loan_no  main_account_active_loan_no  main_account_overdue_no  main_account_outstanding_loan  main_account_sanction_loan  \\\n",
       "count  150000.000000         150000.000000                150000.000000            150000.000000                   1.500000e+05                1.500000e+05   \n",
       "mean    99944.368847              2.447133                     1.045500                 0.153427                   1.670825e+05                2.225586e+05   \n",
       "std     57629.110557              5.197172                     1.952708                 0.542496                   9.808619e+05                2.840313e+06   \n",
       "min         0.000000              0.000000                     0.000000                 0.000000                  -6.678296e+06                0.000000e+00   \n",
       "25%     50069.750000              0.000000                     0.000000                 0.000000                   0.000000e+00                0.000000e+00   \n",
       "50%     99887.500000              1.000000                     0.000000                 0.000000                   0.000000e+00                0.000000e+00   \n",
       "75%    149916.500000              3.000000                     1.000000                 0.000000                   3.545900e+04                6.360000e+04   \n",
       "max    199716.000000            354.000000                   144.000000                23.000000                   9.652492e+07                1.000000e+09   \n",
       "\n",
       "       main_account_disbursed_loan  sub_account_loan_no  sub_account_active_loan_no  sub_account_overdue_no  sub_account_outstanding_loan  sub_account_sanction_loan  \\\n",
       "count                 1.500000e+05        150000.000000               150000.000000           150000.000000                  1.500000e+05               1.500000e+05   \n",
       "mean                  2.221730e+05             0.060133                    0.027967                0.007293                  5.416077e+03               7.385876e+03   \n",
       "std                   2.844075e+06             0.652912                    0.325185                0.111236                  1.617336e+05               1.742796e+05   \n",
       "min                   0.000000e+00             0.000000                    0.000000                0.000000                 -5.746470e+05               0.000000e+00   \n",
       "25%                   0.000000e+00             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "50%                   0.000000e+00             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "75%                   6.150850e+04             0.000000                    0.000000                0.000000                  0.000000e+00               0.000000e+00   \n",
       "max                   1.000000e+09            52.000000                   36.000000                7.000000                  3.603285e+07               2.688820e+07   \n",
       "\n",
       "       sub_account_disbursed_loan  disbursed_amount    asset_cost      branch_id    supplier_id  manufacturer_id        area_id  employee_code_id  mobileno_flag  idcard_flag  \\\n",
       "count                1.500000e+05      150000.00000  1.500000e+05  150000.000000  150000.000000    150000.000000  150000.000000     150000.000000       150000.0     150000.0   \n",
       "mean                 7.268286e+03       54238.47824  7.580399e+04      29.286380     724.978987         2.260600       5.614153       1207.022880            1.0          1.0   \n",
       "std                  1.735824e+05       12835.46104  1.879745e+04      19.335456     625.725640         1.403826       5.513141        812.442074            0.0          0.0   \n",
       "min                  0.000000e+00       13320.00000  3.700000e+04       0.000000       0.000000         0.000000       0.000000          0.000000            1.0          1.0   \n",
       "25%                  0.000000e+00       46973.00000  6.571900e+04      11.000000     212.000000         1.000000       1.000000        494.000000            1.0          1.0   \n",
       "50%                  0.000000e+00       53703.00000  7.092500e+04      28.000000     544.000000         2.000000       4.000000       1107.000000            1.0          1.0   \n",
       "75%                  0.000000e+00       60220.00000  7.913000e+04      45.000000    1091.000000         2.000000       9.000000       1833.000000            1.0          1.0   \n",
       "max                  2.688820e+07      990572.00000  1.628992e+06      81.000000    2933.000000         9.000000      21.000000       3255.000000            1.0          1.0   \n",
       "\n",
       "        Driving_flag  passport_flag   credit_score  main_account_monthly_payment  sub_account_monthly_payment  last_six_month_new_loan_no  last_six_month_defaulted_no  \\\n",
       "count  150000.000000  150000.000000  150000.000000                  1.500000e+05                 1.500000e+05               150000.000000                150000.000000   \n",
       "mean        0.023013       0.002153     291.228720                  1.295898e+04                 2.938682e+02                    0.384900                     0.095687   \n",
       "std         0.149946       0.046354     339.282431                  1.508468e+05                 1.304782e+04                    0.962877                     0.382359   \n",
       "min         0.000000       0.000000       0.000000                  0.000000e+00                 0.000000e+00                    0.000000                     0.000000   \n",
       "25%         0.000000       0.000000       0.000000                  0.000000e+00                 0.000000e+00                    0.000000                     0.000000   \n",
       "50%         0.000000       0.000000      14.000000                  0.000000e+00                 0.000000e+00                    0.000000                     0.000000   \n",
       "75%         0.000000       0.000000     680.000000                  1.989000e+03                 0.000000e+00                    0.000000                     0.000000   \n",
       "max         1.000000       1.000000     890.000000                  2.076655e+07                 3.246710e+06                   35.000000                    20.000000   \n",
       "\n",
       "         average_age  credit_history    enquirie_no  loan_to_asset_ratio  total_account_loan_no  sub_account_inactive_loan_no  total_inactive_loan_no  \\\n",
       "count  150000.000000   150000.000000  150000.000000        150000.000000          150000.000000                 150000.000000           150000.000000   \n",
       "mean        8.027107       13.128353       0.203433             0.723558               2.507267                      1.401633                0.032167   \n",
       "std        13.830386       21.125146       0.696590             0.113621               5.273201                      3.924056                0.429154   \n",
       "min         0.000000        0.000000       0.000000             0.124130               0.000000                      0.000000                0.000000   \n",
       "25%         0.000000        0.000000       0.000000             0.664456               0.000000                      0.000000                0.000000   \n",
       "50%         0.000000        0.000000       0.000000             0.741398               1.000000                      0.000000                0.000000   \n",
       "75%        13.000000       20.000000       0.000000             0.809578               3.000000                      1.000000                0.000000   \n",
       "max       117.000000      117.000000      28.000000             0.937987             354.000000                    344.000000               42.000000   \n",
       "\n",
       "       main_account_inactive_loan_no  total_overdue_no  total_outstanding_loan  total_sanction_loan  total_disbursed_loan  total_monthly_payment  outstanding_disburse_ratio  \\\n",
       "count                  150000.000000     150000.000000            1.500000e+05         1.500000e+05          1.500000e+05           1.500000e+05                   150000.00   \n",
       "mean                        1.433800          0.160720            1.724986e+05         2.299445e+05          2.294413e+05           1.325285e+04                         inf   \n",
       "std                         3.964609          0.557779            9.969156e+05         2.847267e+06          2.850957e+06           1.515095e+05                         NaN   \n",
       "min                         0.000000          0.000000           -6.678296e+06         0.000000e+00          0.000000e+00           0.000000e+00                  -110000.33   \n",
       "25%                         0.000000          0.000000            0.000000e+00         0.000000e+00          0.000000e+00           0.000000e+00                        1.00   \n",
       "50%                         0.000000          0.000000            0.000000e+00         0.000000e+00          0.000000e+00           0.000000e+00                        1.00   \n",
       "75%                         1.000000          0.000000            3.788800e+04         6.690000e+04          6.500000e+04           2.076000e+03                        1.26   \n",
       "max                       344.000000         23.000000            9.652492e+07         1.000000e+09          1.000000e+09           2.076655e+07                         inf   \n",
       "\n",
       "       main_account_tenure  sub_account_tenure  disburse_to_sactioned_ratio  active_to_inactive_act_ratio  year_of_birth  disbursed_date   Credit_level  employment_type  \\\n",
       "count         1.500000e+05        1.500000e+05                 1.500000e+05                 150000.000000  150000.000000        150000.0  150000.000000    150000.000000   \n",
       "mean          5.169842e+04        2.773138e+03                 6.506428e+02                      1.438740    1984.867900          2019.0       3.132360         0.487507   \n",
       "std           2.614563e+06        1.043622e+05                 1.312314e+05                      0.789844       9.813379             0.0       5.268384         0.561527   \n",
       "min           0.000000e+00        0.000000e+00                 0.000000e+00                      1.000000    1950.000000          2019.0      -1.000000         0.000000   \n",
       "25%           0.000000e+00        0.000000e+00                 1.000000e+00                      1.000000    1978.000000          2019.0      -1.000000         0.000000   \n",
       "50%           0.000000e+00        0.000000e+00                 1.000000e+00                      1.000000    1987.000000          2019.0      -1.000000         0.000000   \n",
       "75%           2.500000e+01        0.000000e+00                 1.000000e+00                      1.670000    1993.000000          2019.0       8.000000         1.000000   \n",
       "max           1.000000e+09        1.980000e+07                 5.000000e+07                     18.000000    2001.000000          2019.0      13.000000         2.000000   \n",
       "\n",
       "                 age   loan_default  \n",
       "count  150000.000000  150000.000000  \n",
       "mean       34.132100       0.176967  \n",
       "std         9.813379       0.381642  \n",
       "min        18.000000       0.000000  \n",
       "25%        26.000000       0.000000  \n",
       "50%        32.000000       0.000000  \n",
       "75%        41.000000       0.000000  \n",
       "max        69.000000       1.000000  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:35:51.505267Z",
     "start_time": "2021-07-14T12:35:51.470265Z"
    }
   },
   "outputs": [],
   "source": [
    "feature, label = train.iloc[:, 1:-1], train.loan_default"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:35:53.361374Z",
     "start_time": "2021-07-14T12:35:53.198364Z"
    }
   },
   "outputs": [],
   "source": [
    "x_train, x_test, y_train, y_test = train_test_split(feature, label, \n",
    "                                                    test_size=0.4, \n",
    "                                                    random_state=2021)\n",
    "x_valid, x_test, y_valid, y_test = train_test_split(x_test, y_test, \n",
    "                                                    test_size=0.5, \n",
    "                                                    random_state=2021)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:36:46.163394Z",
     "start_time": "2021-07-14T12:36:43.889264Z"
    }
   },
   "outputs": [],
   "source": [
    "model = LogisticRegression(class_weight='balanced').fit(x_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:48:40.981279Z",
     "start_time": "2021-07-14T12:48:40.885273Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.44145619156599175\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.86      0.42      0.57     24666\n",
      "           1       0.21      0.69      0.32      5334\n",
      "\n",
      "    accuracy                           0.47     30000\n",
      "   macro avg       0.53      0.56      0.44     30000\n",
      "weighted avg       0.75      0.47      0.52     30000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "pred = model.predict(x_valid)\n",
    "print(f1_score(y_valid, pred, average='macro'))\n",
    "print(classification_report(y_valid, pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:39:53.381102Z",
     "start_time": "2021-07-14T12:39:53.222093Z"
    }
   },
   "outputs": [],
   "source": [
    "test = pd.read_csv(r\"D:/LKM/vehicle_loan_default/data/test.csv\")\n",
    "test['outstanding_disburse_ratio'] = test['outstanding_disburse_ratio'].replace([np.inf, -np.inf], 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:39:55.965250Z",
     "start_time": "2021-07-14T12:39:55.934248Z"
    }
   },
   "outputs": [],
   "source": [
    "v_test = test.iloc[:, 1:]\n",
    "test['loan_default'] = model.predict(v_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-07-14T12:40:51.947452Z",
     "start_time": "2021-07-14T12:40:51.874448Z"
    }
   },
   "outputs": [],
   "source": [
    "test[['customer_id', 'loan_default']].to_csv(\"D:/LKM/vehicle_loan_default/data/result.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:lkm]",
   "language": "python",
   "name": "lkm"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
